<?php

include 'class.twitter.php';
include 'config.php';

header('Content-type: text/plain');

$query = "SELECT users.id, users.screen_name FROM users, status WHERE status.in_reply_to_user_id <> '' AND status.user_id = users.id GROUP BY users.id;";
$result  = mysql_query($query);
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}
$users = array();
while ($row = mysql_fetch_assoc($result)) {
    $users[$row['id']] = $row['screen_name'];
}
echo implode(",", $users)."\n";

$query = "SELECT user_id, in_reply_to_user_id FROM STATUS WHERE in_reply_to_user_id <> '';";
$result  = mysql_query($query);
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}
while ($row = mysql_fetch_assoc($result)) {
	foreach ($users as $id => $screen_name) {
		if (($id==$row['user_id'])||($id==$row['in_reply_to_user_id'])) {
			echo '1';
		} else {
			echo '0';
		}
		if ($screen_name<>end($users)) echo ',';
	}
    echo "\n";
}

?>